//index.js
//获取应用实例
var app = getApp()
Page({
  data: {
    selectHide: false,
    inputValue: '',
    getSearch: [],
    clearInput: false,
    modalHidden: true
  },
  bindInput: function(e) {
    this.setData({
      inputValue: e.detail.value
    })
    if (e.detail.value != '') {
      this.setData({
        clearInput: true
      })
    } else {
      this.setData({
        clearInput: false
      })

    }
    console.log('bindInput' + this.data.inputValue)
  },
  setSearchStorage: function() {
    let data;
    let localStorageValue = [];
    if (this.data.inputValue != '') {
      //调用API从本地缓存中获取数据
      var searchData = wx.getStorageSync('searchData') || []
      searchData.push(this.data.inputValue)
      wx.setStorageSync('searchData', searchData)
      app.globalData.searchContent = this.data.inputValue;
      
      wx.switchTab({
        url: '../business/business'
      })
    } else {
      console.log('空白的你搜个jb')
    }
   
  },
  modalChangeConfirm: function() {
    wx.setStorageSync('searchData', [])
    this.setData({
      modalHidden: true
    })

   
    this.getlist();

  },
  modalChangeCancel: function() {
    this.setData({
      modalHidden: true
    })
  },
  clearSearchStorage: function() {
    this.setData({
      modalHidden: false
    })
    // this.onLoad();
  },
  onLoad: function() {
    console.log('search is onLoad');
  },
  onShow: function() {
    this.getlist()

  },
  //获取数据
  getlist(){
    var getSearch = wx.getStorageSync('searchData');
    this.setData({
      getSearch: getSearch,
      inputValue: ''
    })
  },
  localSearch(e){
    app.globalData.searchContent = e.currentTarget.dataset.name;
    wx.switchTab({
      url: '../business/business'
    })

  },
  //进入后台回调
  onHide: function() {
    console.log('search is onHide')
    // wx.redirectTo({
    //   url: '../search/search'
    // })
  },
  bindchange: function(e) {
    console.log('bindchange')
  },
  clearInput: function() {
    this.setData({
      inputValue: ''
    })
  }
})